import 'package:flutter/material.dart';
import 'package:flutter_news/common/utils/utils.dart';
import 'package:flutter_news/common/values/values.dart';

/// 扁平的圆角按钮
Widget btnFlatButtonWidget({
  required VoidCallback onPressed,
  double width = 140,
  double height = 44,
  String btnText = "Button",
  Color bgColor = AppColors.primaryElement,
  Color fontColor = AppColors.primaryElementText,
  double fontSize = 18,
  String fontFamily = FontFamily.avenir,
  FontWeight fontWeight = FontWeight.w400,
}) {
  return TextButton(
    onPressed: onPressed,
    child: Text(
      btnText,
      textScaleFactor: 1.0,
    ),
    style: ButtonStyle(
      // 设置按钮文本颜色
      foregroundColor: MaterialStateProperty.all(fontColor),
      // 设置按钮的背景颜色
      backgroundColor: MaterialStateProperty.all(bgColor),

      // 在这里设置按钮文本颜色无效，要使用 foregroundColor 进行设置
      textStyle: MaterialStateProperty.all(
        TextStyle(
          fontSize: duSetFontSize(fontSize),
          fontFamily: fontFamily,
          fontWeight: fontWeight,
          height: 1,
        ),
      ),

      // 设置按钮的边框和圆角
      shape: MaterialStateProperty.all(
        RoundedRectangleBorder(
          borderRadius: Radii.k6pxRadius,
        ),
      ),

      // 设置按钮的宽度和高度
      fixedSize: MaterialStateProperty.all(
        Size(
          duSetWidth(width),
          duSetHeight(height),
        ),
      ),
    ),
  );
}

/// 第三方按钮
Widget btnFlatButtonBorderOnlyWidget({
  required VoidCallback onPressed,
  required String iconFileName,
  double width = 88,
  double height = 44,
}) {
  return TextButton(
    onPressed: onPressed,
    child: Image.asset(iconFileName),
    style: ButtonStyle(
      fixedSize: MaterialStateProperty.all(
        Size(
          duSetWidth(width),
          duSetHeight(height),
        ),
      ),
      shape: MaterialStateProperty.all(
        RoundedRectangleBorder(
          borderRadius: Radii.k6pxRadius,
        ),
      ),
    ),
  );
}
